package com.senseuni.common.dialog.indicator;


import android.animation.ValueAnimator;
import android.view.animation.LinearInterpolator;

public class BallZigZagDeflectIndicator extends BallZigZagIndicator {

    @Override
    public void createAnimation() {
        float startX = getWidth() / 6f;
        float startY = getWidth() / 6f;

        for (int i = 0; i < 2; i++) {
            final int index = i;
            ValueAnimator translateXAnim = ValueAnimator.ofFloat(startX, getWidth() - startX, startX, getWidth() - startX, startX);
            if (i == 1) {
                translateXAnim = ValueAnimator.ofFloat(getWidth() - startX, startX, getWidth() - startX, startX, getWidth() - startX);
            }
            ValueAnimator translateYAnim = ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY);
            if (i == 1) {
                translateYAnim = ValueAnimator.ofFloat(getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY);
            }

            translateXAnim.setDuration(2000);
            translateXAnim.setInterpolator(new LinearInterpolator());
            translateXAnim.setRepeatCount(-1);
            translateXAnim.addUpdateListener(animation -> {
                translateX[index] = (Float) animation.getAnimatedValue();
                postInvalidate();
            });
            translateXAnim.start();
            addAnimator(translateXAnim);

            translateYAnim.setDuration(2000);
            translateYAnim.setInterpolator(new LinearInterpolator());
            translateYAnim.setRepeatCount(-1);
            translateYAnim.addUpdateListener(animation -> {
                translateY[index] = (Float) animation.getAnimatedValue();
                postInvalidate();
            });
            translateYAnim.start();
            addAnimator(translateYAnim);
        }
    }

}
